/*
 * ChildFieldFrame.java
 *
 * Created on __DATE__, __TIME__
 */

package com.mind.xgame.tools.message;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.util.Vector;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.GroupLayout;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;
import javax.swing.table.DefaultTableModel;

import com.mind.xgame.tools.config.DataBaseType;
import com.mind.xgame.tools.config.DataBigType;
import com.mind.xgame.tools.config.ToolsConf;
import com.mind.xgame.tools.util.MessageUtil;
import com.mind.xgame.tools.util.WarningPanle;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
/**
 *
 * @author __USER__
 */
public class MainFrame extends javax.swing.JFrame {
	private FieldModel nowField = null;
	private Vector<ModuleModel> moduleModels = new Vector<ModuleModel>();
	private ModuleModel currModule = null;
	private MessageModel currMessageModel = null;
	private WarningPanle warningPanle=null;
	
	/** Creates new form ChildFieldFrame */
	public MainFrame() {
		initComponents();
		initData();
		this.setLocationRelativeTo(null);
		warningPanle=new WarningPanle(this, true);
	}
	private static Vector<String> getColumnName(){
		Vector<String> columnsName = new Vector<String>();
		columnsName.add("类型");
		columnsName.add("名称");
		columnsName.add("desc");
		return columnsName;
	}
	private void showData() {
		this.jTable1.setModel(new javax.swing.table.DefaultTableModel(
				MessageModel.getColumnsData(currMessageModel),
				getColumnName()) {
			@Override
			public boolean isCellEditable(int row, int column) {
				if (column % 3 == 0) {
					return false;
				} else {
					return true;
				}
			}
		});
		if(this.currMessageModel!=null&&this.currMessageModel.getName()!=null
				&&this.currMessageModel.getName().length()>0){
			this.jTextField3.setText(this.currMessageModel.getName());	
		}else{
			this.jTextField3.setText("");	
		}
		if(this.currMessageModel!=null
				&&this.currMessageModel.getName()!=null
				&&this.currMessageModel.getName().length()>0){
			this.jTextField4.setText(this.currMessageModel.getDesc());
		}else{
			this.jTextField4.setText("");
		}
		if(this.moduleModels.size()==0){
			this.jCheckBox1.setEnabled(false);
			this.jCheckBox1.setSelected(true);
			this.jComboBox3.setEnabled(false);
		}
		if(currModule.getMessageModels().size()==0){
			this.jComboBox2.setEnabled(false);
			this.jCheckBox2.setSelected(true);
			this.jCheckBox2.setEnabled(false);
		}
	}
	private void initData() {
		moduleModels= MessageUtil.loadMessages();
		if(moduleModels.size()>0){
			currModule=moduleModels.get(0);
		}else{
			currModule=new ModuleModel();
			currModule.setId(MessageUtil.createModuleId(moduleModels));
		}
		if(this.currModule.getMessageModels().size()==0){
			currMessageModel = MessageUtil.createNewMessageModel();
		}else{
			currMessageModel=this.currModule.getMessageModels().get(0);
		}
		showData();
		this.jComboBox1.setModel(new DefaultComboBoxModel(ToolsConf.getInstance().getDataBaseType().toArray()));
		this.jComboBox2.setModel(new DefaultComboBoxModel(currModule.getMessageModels()));
		this.jComboBox3.setModel(new DefaultComboBoxModel<ModuleModel>(moduleModels));
		this.jComboBox4.setModel(new DefaultComboBoxModel(ToolsConf.getInstance().getDataBigTypes().toArray()));
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	
	//GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		jComboBox1 = new javax.swing.JComboBox();
		jLabel1 = new javax.swing.JLabel();
		jLabel2 = new javax.swing.JLabel();
		name1 = new javax.swing.JTextField();
		jLabel3 = new javax.swing.JLabel();
		jTextField2 = new javax.swing.JTextField();
		jScrollPane1 = new javax.swing.JScrollPane();
		{
			jCheckBox2 = new JCheckBox();
			jCheckBox2.setText("new");
			jCheckBox2.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					jCheckBox2ActionPerformed(evt);
				}
			});
		}
		{
			jCheckBox1 = new JCheckBox();
			jCheckBox1.setText("new");
			jCheckBox1.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					jCheckBox1ActionPerformed(evt);
				}
			});
		}
		{
			ComboBoxModel jComboBox4Model = 
					new DefaultComboBoxModel(
							new String[] { "基本类型", "协议","List" });
			jComboBox4 = new JComboBox();
			jComboBox4.setModel(jComboBox4Model);
			jComboBox4.setOpaque(false);
			jComboBox4.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					jComboBox4ActionPerformed(evt);
				}
			});
		}
		{
			jLabel10 = new JLabel();
			jLabel10.setText("\u53d8\u91cf\u7c7b\u578b");
		}
		jTable1 = new javax.swing.JTable();
		jButton1 = new javax.swing.JButton();
		jButton2 = new javax.swing.JButton();
		jButton3 = new javax.swing.JButton();
		jComboBox2 = new javax.swing.JComboBox();
		jLabel4 = new javax.swing.JLabel();
		jTextField3 = new javax.swing.JTextField();
		jLabel5 = new javax.swing.JLabel();
		jTextField4 = new javax.swing.JTextField();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		setResizable(false);

		jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
				"Item 1", "Item 2", "Item 3", "Item 4" }));
		jComboBox1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				jComboBox1ActionPerformed(evt);
			}
		});

		jLabel1.setText("\u5177\u4f53\u7c7b\u578b");

		jLabel2.setText("\u540d\u79f0");

		name1.setName("name1");

		jLabel3.setText("\u6ce8\u91ca\uff1a");

		jTable1.setFont(new java.awt.Font("微软雅黑", 0, 18));
		jTable1.setModel(new javax.swing.table.DefaultTableModel(
				new Object[][] { { null, null, null, null },
						{ null, null, null, null }, { null, null, null, null },
						{ null, null, null, null } }, new String[] { "Title 1",
						"Title 2", "Title 3", "Title 4" }));
		jTable1.setRowHeight(22);
		jScrollPane1.setViewportView(jTable1);

		jButton1.setText("add");
		jButton1.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton1ActionPerformed(evt);
			}
		});

		jButton2.setText("delete");
		jButton2.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton2ActionPerformed(evt);
			}
		});

		jButton3.setText("save");
		{
			ComboBoxModel<ModuleModel> jComboBox3Model = 
					new DefaultComboBoxModel(
							new String[] { "Item One", "Item Two" });
			jComboBox3 = new JComboBox<ModuleModel>();
			jComboBox3.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					jComboBox3ActionPerformed(evt);
				}
			});
			jComboBox3.setModel(jComboBox3Model);
		}
		{
			jTextField1 = new JTextField();
			jTextField1.setText("1000");
		}
		{
			jLabel6 = new JLabel();
			jLabel6.setText("\u8d77\u59cb\u534f\u8bae\u53f7\uff1a");
		}
		{
			jTextField5 = new JTextField();
			jTextField5.setText("000");
		}
		{
			jLabel7 = new JLabel();
			jLabel7.setText("\u540d\u79f0");
		}
		{
			jLabel8 = new JLabel();
			jLabel8.setText("\u529f\u80fd\u6a21\u5757");
		}
		{
			jLabel9 = new JLabel();
			jLabel9.setText("\u534f        \u8bae");
		}
		jButton3.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton3ActionPerformed(evt);
			}
		});

		jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
				"Item 1", "Item 2", "Item 3", "Item 4" }));
		jComboBox2.addItemListener(new java.awt.event.ItemListener() {
			public void itemStateChanged(java.awt.event.ItemEvent evt) {
				jComboBox2ItemStateChanged(evt);
			}
		});

		jLabel4.setText("\u540d\u79f0");

		jLabel5.setText("\u6ce8\u91ca\uff1a");

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout.setVerticalGroup(layout.createSequentialGroup()
			.addContainerGap()
			.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
			    .addComponent(jComboBox3, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 28, GroupLayout.PREFERRED_SIZE)
			    .addComponent(jLabel8, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			    .addComponent(jTextField1, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			    .addComponent(jLabel6, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			    .addComponent(jTextField5, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			    .addComponent(jLabel7, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			    .addComponent(jCheckBox1, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 18, GroupLayout.PREFERRED_SIZE))
			.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
			.addGroup(layout.createParallelGroup()
			    .addGroup(GroupLayout.Alignment.LEADING, layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
			        .addComponent(jTextField3, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			        .addComponent(jLabel4, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			        .addComponent(jLabel5, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			        .addComponent(jTextField4, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			        .addComponent(jComboBox2, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
			    .addGroup(layout.createSequentialGroup()
			        .addGap(7)
			        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
			            .addComponent(jLabel9, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			            .addComponent(jCheckBox2, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 18, GroupLayout.PREFERRED_SIZE))))
			.addGap(29)
			.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
			    .addComponent(jComboBox4, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 28, GroupLayout.PREFERRED_SIZE)
			    .addComponent(jComboBox1, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			    .addComponent(jLabel1, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			    .addComponent(jLabel10, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
			.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
			.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
			    .addComponent(name1, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			    .addComponent(jLabel2, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			    .addComponent(jLabel3, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			    .addComponent(jTextField2, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
			.addGap(0, 17, Short.MAX_VALUE)
			.addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 439, GroupLayout.PREFERRED_SIZE)
			.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 1, GroupLayout.PREFERRED_SIZE)
			.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
			    .addComponent(jButton1, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			    .addComponent(jButton2, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			    .addComponent(jButton3, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
			.addContainerGap(48, 48));
		layout.setHorizontalGroup(layout.createSequentialGroup()
			.addContainerGap()
			.addGroup(layout.createParallelGroup()
			    .addGroup(layout.createSequentialGroup()
			        .addGroup(layout.createParallelGroup()
			            .addComponent(jLabel10, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 64, GroupLayout.PREFERRED_SIZE)
			            .addComponent(jLabel9, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 64, GroupLayout.PREFERRED_SIZE)
			            .addComponent(jLabel8, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 64, GroupLayout.PREFERRED_SIZE))
			        .addGap(7)
			        .addGroup(layout.createParallelGroup()
			            .addComponent(jComboBox4, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 154, GroupLayout.PREFERRED_SIZE)
			            .addComponent(jComboBox2, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 154, GroupLayout.PREFERRED_SIZE)
			            .addComponent(jComboBox3, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 154, GroupLayout.PREFERRED_SIZE))
			        .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
			        .addGroup(layout.createParallelGroup()
			            .addComponent(jCheckBox2, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
			            .addComponent(jCheckBox1, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE))
			        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
			        .addGroup(layout.createParallelGroup()
			            .addGroup(layout.createSequentialGroup()
			                .addGap(0, 0, Short.MAX_VALUE)
			                .addComponent(jLabel1, GroupLayout.PREFERRED_SIZE, 64, GroupLayout.PREFERRED_SIZE))
			            .addGroup(layout.createSequentialGroup()
			                .addPreferredGap(jLabel1, jLabel2, LayoutStyle.ComponentPlacement.INDENT)
			                .addGroup(layout.createParallelGroup()
			                    .addComponent(jLabel2, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			                    .addGroup(layout.createSequentialGroup()
			                        .addComponent(jLabel4, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			                        .addGap(0, 0, Short.MAX_VALUE))
			                    .addGroup(layout.createSequentialGroup()
			                        .addComponent(jLabel7, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			                        .addGap(0, 0, Short.MAX_VALUE)))
			                .addGap(21)))
			        .addGap(7)
			        .addGroup(layout.createParallelGroup()
			            .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
			                .addComponent(jButton2, GroupLayout.PREFERRED_SIZE, 91, GroupLayout.PREFERRED_SIZE)
			                .addGap(74))
			            .addComponent(name1, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 165, GroupLayout.PREFERRED_SIZE)
			            .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
			                .addComponent(jComboBox1, GroupLayout.PREFERRED_SIZE, 154, GroupLayout.PREFERRED_SIZE)
			                .addGap(11))
			            .addComponent(jTextField3, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 165, GroupLayout.PREFERRED_SIZE)
			            .addComponent(jTextField5, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 165, GroupLayout.PREFERRED_SIZE))
			        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
			        .addGroup(layout.createParallelGroup()
			            .addGroup(layout.createSequentialGroup()
			                .addGroup(layout.createParallelGroup()
			                    .addComponent(jLabel3, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
			                    .addComponent(jLabel5, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
			                .addGap(8)
			                .addGroup(layout.createParallelGroup()
			                    .addComponent(jTextField2, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 164, GroupLayout.PREFERRED_SIZE)
			                    .addComponent(jTextField4, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 164, GroupLayout.PREFERRED_SIZE)))
			            .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
			                .addComponent(jLabel6, GroupLayout.PREFERRED_SIZE, 102, GroupLayout.PREFERRED_SIZE)
			                .addGap(12)
			                .addGroup(layout.createParallelGroup()
			                    .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
			                        .addComponent(jButton3, GroupLayout.PREFERRED_SIZE, 91, GroupLayout.PREFERRED_SIZE)
			                        .addGap(12))
			                    .addComponent(jTextField1, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 103, GroupLayout.PREFERRED_SIZE)))))
			    .addGroup(layout.createSequentialGroup()
			        .addPreferredGap(jLabel10, jScrollPane1, LayoutStyle.ComponentPlacement.INDENT)
			        .addGroup(layout.createParallelGroup()
			            .addGroup(layout.createSequentialGroup()
			                .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 734, GroupLayout.PREFERRED_SIZE)
			                .addGap(0, 0, Short.MAX_VALUE))
			            .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
			                .addGap(36)
			                .addComponent(jButton1, GroupLayout.PREFERRED_SIZE, 91, GroupLayout.PREFERRED_SIZE)
			                .addGap(0, 607, Short.MAX_VALUE)))
			        .addGap(8)))
			.addContainerGap(21, 21));

		pack();
		this.setSize(793, 751);
	}// </editor-fold>
	//GEN-END:initComponents

	private void jComboBox2ItemStateChanged(java.awt.event.ItemEvent evt) {
		this.currMessageModel=(MessageModel) this.jComboBox2.getSelectedItem();
		showData();
	}
	private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
		if(this.jTextField4.getText().length()==0
				||this.jTextField3.getText().length()==0
				||this.jTextField5.getText().length()==0
				||this.currMessageModel.getFields().size()==0){
			this.warningPanle.showMessage("协议不完整！");
			return;
		}
		
		try {
			File file = new File(ToolsConf.MESSAGE_FILE);
			if (!file.exists()) {
				file.createNewFile();
			}
			this.currMessageModel.setName(this.jTextField3.getText());
			this.currMessageModel.setDesc(this.jTextField4.getText());
			this.currMessageModel.setMessageType(MessageUtil.createMessageType(currModule));
			
			this.currModule.setModuleName(this.jTextField5.getText());
			if(this.jCheckBox2.isSelected()){
				for(int i=this.currModule.getMessageModels().size()-1;i>=0;i--){
					if(this.currModule.getMessageModels().get(i).getName()
							.equalsIgnoreCase(this.currMessageModel.getName())){
						this.currModule.getMessageModels().remove(i);
					}
				}
				this.currModule.getMessageModels().add(currMessageModel);
			}
			if(this.jCheckBox1.isSelected()){
				for(int i=this.moduleModels.size()-1;i>=0;i--){
					if(this.moduleModels.get(i).getId()==this.currModule.getId()){
						this.moduleModels.remove(i);
					}
				}
				this.moduleModels.add(this.currModule);
			}
			MessageUtil.writeMessageFile(this.moduleModels);
		} catch (IOException e) {
			e.printStackTrace();
		}
		initData();
	}

	private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
		if (this.jTable1.getSelectedRow() != -1) {
			DefaultTableModel model = (DefaultTableModel) this.jTable1
					.getModel();
			String filedName=(String) model.getValueAt(this.jTable1.getSelectedRow(), 1);
			model.removeRow(this.jTable1.getSelectedRow());
			for(int i=currMessageModel.getFields().size()-1;i>=0;i--){
				if(currMessageModel.getFields().get(i).getName()
						.equalsIgnoreCase(filedName)){
					currMessageModel.getFields().remove(i);
				}
			}
		}
	}

	private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
		if (this.name1.getText().trim().length() > 0) {
			DataBigType bigType=(DataBigType) jComboBox4.getSelectedItem();
			String javaType=null;
			String ccpType=null;
			switch(bigType.getValue()){
			case 0:
			case 1:
				DataBaseType baseType=	(DataBaseType) jComboBox1.getSelectedItem();
				javaType=baseType.getJavaType();
				ccpType=baseType.getCppType();
				break;
			case 2:
				MessageModel message=(MessageModel) jComboBox1.getSelectedItem();
				javaType=message.getName();
				ccpType=javaType+"*";
				break;
			case 3:
				message=(MessageModel) jComboBox1.getSelectedItem();
				javaType="List<"+message.getName()+">";
				ccpType=javaType+"**";
				break;
			}
			
			FieldModel fieldModel = new FieldModel(bigType.getValue(),javaType,ccpType, this.name1.getText().trim(), this.jTextField2
					.getText().trim());
			nowField = fieldModel;
			currMessageModel.getFields().add(nowField);
//			if (jComboBox1.getSelectedItem().equals(DataBaseType.List)) {
//				ChildDialog childDialog = new ChildDialog(this, this.name1
//						.getText().trim(), true);
//				childDialog.setVisible(true);
//				childDialog
//						.addWindowListener(new java.awt.event.WindowAdapter() {
//							public void windowClosed(
//									java.awt.event.WindowEvent e) {
//								nowField.setFields(((ChildDialog) e.getSource())
//										.getModels());
//								showData();
//								((ChildDialog) e.getSource()).setVisible(false);
//							}
//						});
//			}
			showData();

		}

	}

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new MainFrame().setVisible(true);
			}
		});
	}
	
	private void jComboBox1ActionPerformed(ActionEvent evt) {
	}
	
	private void jComboBox4ActionPerformed(ActionEvent evt) {
		DataBigType bigType=(DataBigType) jComboBox4.getSelectedItem();
		switch(bigType.getValue()){
		case 0:
		case 1:
			this.jComboBox1
			.setModel(new DefaultComboBoxModel(ToolsConf.getInstance().getDataBaseType().toArray()));
			break;
		case 2:
			this.jComboBox1.setModel(new DefaultComboBoxModel(MessageUtil.getAllMessages(moduleModels)));
			break;
		case 3:
			this.jComboBox1.setModel(new DefaultComboBoxModel(MessageUtil.getAllMessages(moduleModels)));
			break;
		}
	}
	
	private void jCheckBox1ActionPerformed(ActionEvent evt) {
		if(this.jCheckBox1.isSelected()){
			this.jComboBox3.setEnabled(false);
		}else{
			this.jComboBox3.setEnabled(true);
		}
		showData();
	}
	
	private void jCheckBox2ActionPerformed(ActionEvent evt) {
		if(this.jCheckBox2.isSelected()){
			currMessageModel=new MessageModel();
			this.jComboBox2.setEnabled(false);
		}else{
			currMessageModel=this.currModule.getMessageModels().get(0);
			this.jComboBox2.setEnabled(true);
		}
		showData();
	}
	
	private void jComboBox3ActionPerformed(ActionEvent evt) {
		ModuleModel moduleModel=(ModuleModel) jComboBox4.getSelectedItem();		
		this.currModule=moduleModel;
		showData();
	}

	//GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JButton jButton1;
	private javax.swing.JButton jButton2;
	private javax.swing.JButton jButton3;
	private javax.swing.JComboBox jComboBox1;
	private javax.swing.JComboBox jComboBox2;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel2;
	private javax.swing.JLabel jLabel3;
	private javax.swing.JLabel jLabel4;
	private javax.swing.JLabel jLabel5;
	private JComboBox jComboBox4;
	private JLabel jLabel9;
	private JLabel jLabel8;
	private JLabel jLabel7;
	private JTextField jTextField5;
	private JCheckBox jCheckBox1;
	private JCheckBox jCheckBox2;
	private JLabel jLabel10;
	private JLabel jLabel6;
	private JTextField jTextField1;
	private JComboBox<ModuleModel> jComboBox3;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JTable jTable1;
	private javax.swing.JTextField jTextField2;
	private javax.swing.JTextField jTextField3;
	private javax.swing.JTextField jTextField4;
	private javax.swing.JTextField name1;
	// End of variables declaration//GEN-END:variables

}